import Vuex from 'vuex'
import event from '@/net/event'
import protocal from '@/net/installOrder'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    userAdcd: '',
    sbcj: '',
    sbcjData: [],
    adcd: '',
    adcdName: [],
    adcdId: [],
    model: 0,
    modelData: [
      { name: '时间排序', value: 0 },
      { name: '甲方名称', value: 1 },
      { name: '行政区划', value: 2 }
    ],
    keyword: '',
    listData: []
  },
  mutations: {
    changeUserAdcd (state, value) {
      state.userAdcd = value
    },
    changeSbcj (state, value) {
      state.sbcj = value
    },
    changeSbcjData (state, value) {
      state.sbcjData = value
    },
    changeAdcd (state, value) {
      state.adcd = value
    },
    changeAdcdName (state, value) {
      state.adcdName = value
    },
    changeAdcdId (state, value) {
      state.adcdId = value
    },
    changeModel (state, value) {
      state.model = value
    },
    changeModelData (state, value) {
      state.modelData = value
    },
    changeKeyword (state, value) {
      state.keyword = value
    },
    changeListData (state, value) {
      state.listData = value
    }
  },
  actions: {
    getSBCJ ({state, commit}, vm) {
      vm.$notice.loading.show()
      event.SBCJ(state.adcd).then(res => {
        let arr = res.result.datalist
        arr.unshift({
          GSDM: '',
          GSMC: '全部'
        })
        commit('changeSbcjData', arr)
        vm.$nextTick(() => {
          vm.$notice.loading.hide()
        })
      })
    },
    getAzddList ({state, commit}, vm) {
      vm.$notice.loading.show()
      protocal.getProtocal({
        quyxzqhdm: state.adcd,
        quygsdm: state.sbcj,
        hzxm: state.keyword,
        sort: state.model
      }).then(res => {
        commit('changeListData', res)
        vm.$nextTick(() => {
          vm.$notice.loading.hide()
        })
      })
    }
  }
})
